<template>
  <el-row>
<p style="font-size: xx-large">我的消息</p>
    <el-row :gutter="14" >
      <el-col :span="16" :offset="4">
      <el-card>
        <el-input v-model="input4search" placeholder="通过项目号查询记录"></el-input>
        <el-button  icon="el-icon-search" @click="searchPid" circle></el-button>

        <el-table
        :data="tableData"
        style="width: 100%"
        max-height="370"
              :default-sort = "{prop: 'cCreateTime', order: 'descending'}">


        <el-table-column
          prop="sId"
          label="发送人"
          width="120">
        </el-table-column>
        <el-table-column
          prop="pId"
          label="项目号"
          width="120"
        >
        </el-table-column>
        <el-table-column
          prop="cCreateTime"
          label="发送时间"
          width="120"
        sortable>
        </el-table-column>
        <el-table-column
          prop="cFeedback"
          label="反馈"
          width="120">
        </el-table-column>
        <el-table-column
          prop="cResponseType"
          label="回复类型"
          width="120"
          :filters="[
            {text:'未回复',value:'未回复'},
            {text:'驳回',value:'驳回'},
            {text:'同意',value:'同意'}]"
          :filter-method="filterByPro"
        >
        </el-table-column>
        <el-table-column
          prop="cFileUrl"
          label="阶段性产品"
          width="120">
          <template slot-scope="scope">
            <el-button @click="getFile(scope.row.cFileUrl)">点击下载</el-button>
<!--            <el-link :href="scope.row.cFileUrl">点击查看</el-link>-->
          </template>
        </el-table-column>
    <!--    <el-table-column-->
    <!--      fixed="right"-->
    <!--      label="操作"-->
    <!--      width="120">-->
    <!--      <template slot-scope="scope">-->
    <!--        <el-button-->
    <!--          @click.native.prevent="deleteRow(scope.$index, tableData)"-->
    <!--          type="text"-->
    <!--          size="small">-->
    <!--          移除-->
    <!--        </el-button>-->
    <!--      </template>-->
    <!--    </el-table-column>-->
      </el-table>
      </el-card>
      </el-col>
    </el-row>
  </el-row>
</template>

<script>
  import Global from '../../utils/global'


var responseTypeMap =['未回复','同意','驳回'];
//阶段状态到阶段名称的映射表         //写错了
  export default {
    name: 'Message4Manager',
    data(){
      return {
        input4search:'',
        glo:new Global,
        tableData: [
          { sId:1,
            pId:10,
            cCreateTime: new Date().toDateString(),
            cFeedback:"不行",
            cResponseType:"驳回",
            cFileUrl:"www.baidu.com"
          }
        ],
        tableDataCopy:null,
      }
    },
    methods: {
      searchPid(){
        if(this.input4search == ''){
          this.tableData = this.tableDataCopy;
          return
        }
        this.tableDataCopy = this.tableData;
        this.tableData = []
        for(var i in this.tableDataCopy){
          if(this.tableDataCopy[i].pId == this.input4search){
            this.tableData.push(this.tableDataCopy[i])
          }
        }
      },
      filterByPro(value, row, column){
        const property = column['property'];
        return row[property] === value;
      },
      inserTable (line) {
          this.tableData.push(
            {
              sId:JSON.parse(sessionStorage.getItem('StaffInfo')).sId,
            pId:line.pId,
            cCreateTime: line.cCreateTime,
            cFeedback:line.cFeedback,
            cResponseType:responseTypeMap[line.cResponseType],
            cFileUrl:line.cFileUrl,
            }
          )
        },
      deleteRow(index, rows) {
        rows.splice(index, 1);
      },
      initProjectPage (res) {
        if (1){//可能还需要判断是否获取成功

        }
        console.log(res)

        for (var line in res.data.commitLogList){
          this.inserTable(res.data.commitLogList[line])
        }
        console.log(this.tableData)

      },
      getFile(url){
         var timestamp = (new Date()).valueOf();
         var token = md5("epms" + timestamp);
         window.open("http://47.92.227.185:8080/download/commitLogFile?token="+token+"&timestamp="+timestamp+"&url="+url);
      }

    },
    mounted () {
      let data = {
        sId:JSON.parse(sessionStorage.getItem('StaffInfo')).sId
      }
      this.glo.sendDate(this.glo.server+'staff/GetCommitLog',data,this.initProjectPage)
    },

  }
</script>

<style scoped>

</style>
